import click


def validate_inputs(gender, age, height_cm, weight_kg):
    """
    Validate inputs for the BMR calculation.

    Parameters:
    - gender: str, 'male' or 'female'
    - age: int, age in years
    - height_cm: float, height in centimeters
    - weight_kg: float, weight in kilograms

    Raises:
    - ValueError: if any of the inputs are invalid.
    """
    gender = gender.strip().lower()

    if gender not in ['male', 'female']:
        raise ValueError("Gender should be either 'male' or 'female'.")

    if age <= 0:
        raise ValueError("Age should be a positive integer.")

    if height_cm <= 0:
        raise ValueError("Height should be a positive number in centimeters.")

    if weight_kg <= 0:
        raise ValueError("Weight should be a positive number in kilograms.")

    return gender


def calculate_bmr(gender, age, height_cm, weight_kg):
    """
    Calculate Basal Metabolic Rate (BMR) using Harris-Benedict equation.

    Parameters:
    - gender: str, 'male' or 'female'
    - age: int, age in years
    - height_cm: float, height in centimeters
    - weight_kg: float, weight in kilograms

    Returns:
    - bmr: float, calculated basal metabolic rate
    """
    height_m = height_cm / 100  # convert height to meters

    if gender == 'male':
        bmr = 88.362 + (13.397 * weight_kg) + (4.799 * height_m) - (5.677 * age)
    else:
        bmr = 447.593 + (9.247 * weight_kg) + (3.098 * height_m) - (4.330 * age)

    return bmr


@click.command()
@click.option('--gender', prompt='Enter your gender (male/female)',
              type=click.Choice(['male', 'female'], case_sensitive=False), help="Your gender: 'male' or 'female'")
@click.option('--age', prompt='Enter your age in years', type=int, help="Your age in years")
@click.option('--height_cm', prompt='Enter your height in cm', type=float, help="Your height in centimeters")
@click.option('--weight_kg', prompt='Enter your weight in kg', type=float, help="Your weight in kilograms")
def main(gender, age, height_cm, weight_kg):
    """
    Main function to run the BMR calculator.

    This program calculates your Basal Metabolic Rate (BMR) based on your
    gender, age, height, and weight using the Harris-Benedict equation.
    """
    try:
        # Validate inputs
        gender = validate_inputs(gender, age, height_cm, weight_kg)

        # Calculate BMR
        bmr = calculate_bmr(gender, age, height_cm, weight_kg)

        # Output
        click.echo(f"Your Basal Metabolic Rate (BMR) is: {bmr:.2f} calories/day")

    except ValueError as ve:
        click.echo(f"Input Error: {ve}")
    except Exception as e:
        click.echo(f"An unexpected error occurred: {e}")


if __name__ == "__main__":
    main()
